

const baseUrl = 'https://api-hmugo-web.itheima.net/api/public/v1'
const request = (config) => {
  return new Promise((resolve, reject) => {
    wx.showLoading({
      title: '数据加载中...',
      mask:true
    })
    wx.request({
      ...config,
      url: baseUrl + config.url, 
      success(res) {
        console.log(res)
        if(res.data.meta.status===200&&res.statusCode===200){
          resolve(res.data.message)
        }
        
      },
      fail(err) {
        reject(err)
      },
      complete() {
        wx.hideLoading()
      }
    })
  })
}
const requestAll = (arr)=>{
  return new Promise((resolve, reject)=>{
    wx.showLoading({
      title: '数据加载中...',
    })
    Promise.all(arr).then(arr=>{
      wx.hideLoading()
      resolve(arr)
    })
  })
}
export default {
  request,
  requestAll
}